package cn.ekuma.epos.datalogic.define.dao.erp;

import java.util.List;

import cn.ekuma.data.dao.ViewDAO;

import com.openbravo.bean.erp.viewbean.CustomerAnalysisInfo;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.QBFBuilder;
import com.openbravo.data.loader.SerializerWriteBasic;
import com.openbravo.data.loader.Session;
import com.openbravo.data.loader.StaticSentence;
import com.openbravo.data.loader.query.QBFParameters;

public class CustomerAnalysisInfoDAO extends ViewDAO<CustomerAnalysisInfo> {

	public static String PREF_CUSTOMER="PS.";
	public static String PREF_CUSTOMERCATEGORIES="C.";
	public static String PREF_OPERATION_CUSTOMER_CATEGORIES="OPC.";
	
	public CustomerAnalysisInfoDAO(I_Session s) {
		super(s);
	}

	@Override
	public CustomerAnalysisInfo readValues(DataRead dr,CustomerAnalysisInfo obj) throws BasicException {
		if(obj==null)
			obj=new CustomerAnalysisInfo();
		obj.setKey(dr.getString(1));
		obj.setSearchkey(dr.getString(2));
		obj.setName(dr.getString(3));
		obj.setCard(dr.getString(4));
		obj.setMaxdebt(dr.getDouble(5));
		obj.setCurdate(dr.getTimestamp(6));
		obj.setCurdebt(dr.getDouble(7));
		return obj;
	}

	@Override
	public Class getSuportClass() {
		return CustomerAnalysisInfo.class;
	}
	
	@Override
	public List<CustomerAnalysisInfo> list(Object filter)
			throws BasicException {
		return new StaticSentence(s, new QBFBuilder(
                "SELECT PS.ID,PS.SEARCHKEY,PS.NAME,PS.CARD,PS.MAXDEBT,PS.CURDATE,PS.CURDEBT "
                + "FROM CUSTOMERS PS "
                + "LEFT OUTER JOIN OPERATION_CUSTOMER OP ON PS.ID = OP.CUSTOMER  "
                + "LEFT OUTER JOIN OPERATION_CUSTOMER_CATEGORIES OPC ON OP.OPERATIONCATEGORIE = OPC.ID  "
                + "WHERE ?(QBF_FILTER) ",
                new String[]{"PS.CATEGORY","OPC.ID"}), new SerializerWriteBasic(new Datas[]{Datas.OBJECT, Datas.STRING,Datas.OBJECT, Datas.STRING}), this).list(filter);
	}

	@Override
	public List<CustomerAnalysisInfo> query(QBFParameters filter)
			throws BasicException {
		return new StaticSentence(s, new QBFBuilder("SELECT PS.ID,PS.SEARCHKEY,PS.NAME,PS.CARD,PS.MAXDEBT,PS.CURDATE,PS.CURDEBT "
                + "FROM CUSTOMERS PS "
                + "LEFT OUTER JOIN OPERATION_CUSTOMER OP ON PS.ID = OP.CUSTOMER  "
                + "LEFT OUTER JOIN OPERATION_CUSTOMER_CATEGORIES OPC ON OP.OPERATIONCATEGORIE = OPC.ID  "
                + "WHERE ?(QBF_FILTER) "),null,this).list(filter);
	}
	
	
}
